/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.lujotar.ejb;

import com.lujotar.entities.Tarjeta;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author RamiroHenao
 */
@Stateless
public class TarjetaFacade extends AbstractFacade<Tarjeta> {
    @PersistenceContext(unitName = "LUJOTAR-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public TarjetaFacade() {
        super(Tarjeta.class);
    }
    
    public List<Tarjeta> consultarTarjetaId(String id){
        Query query;
        query = em.createNamedQuery("Tarjeta.findById");
        if(id != null && !id.equals("")){
            query.setParameter("id",Integer.valueOf(id));
        }else{
            query.setParameter("id",Integer.valueOf(0));
        }
        return query.getResultList();
    }
    
    public List<Tarjeta> consultarTarjetas(){
        Query query;
        query = em.createNamedQuery("Tarjeta.findAll");
        return query.getResultList();
    }
    
    public void crearTarjeta(Tarjeta tarjeta) { 
        em.persist(tarjeta); 
    }
    
    public void anularTarjeta(Tarjeta tarjeta) { 
        em.merge(tarjeta);
    }
    
}
